package top.tagao.m03_beHavioralPatterns.b_12_Iterator.spammer;

import top.tagao.m03_beHavioralPatterns.b_12_Iterator.iterators.ProfileIterator;
import top.tagao.m03_beHavioralPatterns.b_12_Iterator.profile.Profile;
import top.tagao.m03_beHavioralPatterns.b_12_Iterator.social_networks.SocialNetwork;


/**
 * @author Viktor_Liu
 * @Date 2022/8/14 23:37
 */
public class SocialSpammer {
    public SocialNetwork network;
    public ProfileIterator iterator;

    public SocialSpammer(SocialNetwork network) {
        this.network = network;
    }

    public void sendSpamToFriends(String profileEmail, String message) {
        System.out.println("\nIterating over friends...\n");
        //拿到迭代器，发送消息给朋友
        iterator = network.createFriendsIterator(profileEmail);
        while (iterator.hasNext()){
            Profile profile = iterator.getNext();
            sendMessage(profile.getEmail(), message);
        }
    }
    public void sendSpamToCoworkers(String profileEmail, String message) {
        System.out.println("Iterating over coworkers...\n");
        iterator = network.createCoworkersIterator(profileEmail);
        while (iterator.hasNext()){
            Profile profile = iterator.getNext();
            sendMessage(profile.getEmail(), message);
        }


    }
    private void sendMessage(String email, String message) {
        System.out.println("Sent message to: '" + email + "'. Message body: '" + message + "'");
    }

}
